﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SSS.AlphaNN.Components
{
    public partial class Neuron : Dummy
    {
       
        /// <summary>
        /// Смещение нейрона
        /// </summary>
        public double Offset
        {
            get; set;
        }

        /// <summary>
        /// Номер функции активации
        /// </summary>
        public int IdActivationFunction
        {
            get; set;
        }

       
        /// <summary>
        /// Конструктор
        /// </summary>
        public Neuron( UserControl parent ):base()
        {
            

            InitializeComponent();

           
            //System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //gp.AddArc( 0, 0, this.Width - 1, this.Height - 1, 0, 360 );
            //this.Region = new Region( gp );

            this.Parent = parent;
            //инициализация функции активации и параметров к ней и смещения для нейрона
            IdActivationFunction = 0;
            ParametersForActivationFunction = new List<object>() {1};
            Offset = 0;

            this.BackColor = Color.GhostWhite;

            this.Paint += new PaintEventHandler( Neuron_Paint );
        }

        /// <summary>
        /// 
        /// </summary>
        long _id;

        /// <summary>
        /// 
        /// </summary>
        public override void CreateSlots()
        {
            base.CreateSlots();

            Slot slot = new Slot();

            slot.Name = "slot1";//вот эта строчка  меня убила
            ( this.Parent as WorkGround ).Controls.Add( slot );
            
            //this.Controls.Add( slot );
            //slot.Left = base.NoneScaleLocation.X + 0;
            //slot.Top = base.NoneScaleLocation.Y + base.NoneScaleSize.Height / 2 - slot.NoneScaleSize.Height / 2;
            base.Slots.Add( slot );
            slot.Visible = false;
            slot.Owner = this;


            slot = new Slot();
            
            slot.Name = "slot2";
            ( this.Parent as WorkGround ).Controls.Add( slot );
            slot.Left = 0;// base.Location.X + base.Width - slot.Width;
            slot.Top = 0; // base.Location.Y + base.Height / 2 - slot.Height / 2;
            base.Slots.Add( slot );
            slot.Visible = false;
            slot.Owner = this;

            //slot2.Visible = true;
        }

        /// <summary>
        /// 
        /// </summary>
        public override void ReLocate()
        {
            base.ReLocate();

            if ( base.Slots.Count > 0 )
            {
                base.Slots[0].Left = base.Location.X + 0;
                base.Slots[0].Top = base.Location.Y + this.Height / 2 - base.Slots[0].Height / 2;

                base.Slots[1].Left = this.Location.X + this.Width - base.Slots[1].Width;
                base.Slots[1].Top = this.Location.Y + this.Height / 2 - base.Slots[1].Height / 2;
            }

        }


        public override void Scale()
        {
            base.Scale();

            if ( base.Slots.Count > 0 )
            {
                Slot slot = new Slot();

                for ( int i = 0; i < base.Slots.Count; i++ )
                {
                    slot = base.Slots[i];

                    slot.Size = new Size( ( int )( slot.NoneScaleSize.Width + slot.NoneScaleSize.Width * Zoom / 100 ), ( int )( slot.NoneScaleSize.Height + slot.NoneScaleSize.Height * Zoom / 100 ) );
                }
            }
        }
        
        //protected override void OnResize( EventArgs e )
        //{
        //    base.OnResize( e );         
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Neuron_Paint( object sender, PaintEventArgs e )
        {
            // Draw border
            e.Graphics.DrawEllipse( new Pen( base.borderColor ), 1, 1, this.Width - 3, this.Height - 3 );
        }

        //public override void DoAnimate()
        //{          
        //}


    }
}
